//原文链接：https://blog.csdn.net/ITSOK_123/article/details/123865720
//单向双指针
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int size = nums.size();
        int last=0,first=0;
        for(first =0 ;first<size;first++){
            if(nums[first] != val)
                nums[last++] = nums[first];
        }
        return last;
    }
};

//双向双指针
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int left = 0;
        int right = nums.size() - 1;
        while(left<=right){
        //找左边值为val的元素备用
            while(left<=right && nums[left] != val)
                ++left;
        //找右边值不为val的元素替换到前面
            while(left<=right && nums[right] == val)
                --right;
         //注意边界条件
            if(left<right){
                 nums[left++] = nums[right--];
                } 
        }
        //最后的left指向的就是末尾元素的下一个位置
        return left;   
    }
};
